<template>
  <ul class="article">
    <!-- 解决key重复问题 -->
    <li v-for="(item,index) in dataList" :key="`${item._id}-${index}`" @click="$router.push(`/detail?aId=${item._id}`)">
      <div class="left"><img :src="item.src" alt=""></div>
      <div class="right">
        <h5>{{ item.title }}</h5>
        <div class="detail"><span class="avatar"><img :src="item.avatar" alt=""></span>
        <span class="name">{{ item.userName }}</span>
        <span class="time">{{ transDate(item.time) }}</span>
        </div>
        <p>{{ item.introduce }}</p>
      </div>
      <div class="more el-icon-more-outline"
                      @click.stop="clickMore"
                       v-if="$store.state.user.userInf.admin"
                      >
                  <div class="option">
                    <div class="op"
                    @click.stop="deleteArticle(item._id,index)"
                    ><span class="el-icon-delete"></span>删除</div>
                    <div class="op"
                    @click.stop="pushInto(item)"
                    ><span class="el-icon-edit-outline"></span>编辑</div>
                  </div>
                  </div>
    </li>

    
  </ul>
</template>

<script>
import { deleteArticle } from '@/api/article';
// import { edify } from '@/api/article';
export default {
  data(){
    return{
      list:[],
    }
  },
      props:['dataList'],
      methods:{
        pushInto(item){
          this.$router.push({
            path:'/edify',
            query:{
              title:item.title,
              introduce:item.introduce,
              text:item.text,
              mdText:item.mdText,
              aId:item._id
            }
          })
        },
        
        deleteArticle(id,index){

          this.$confirm('此操作将永久删除该文章, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
       const data = await deleteArticle(id)
        if (data.code === '000') {
          this.$message({
            message: '删除成功哦~',
            type: 'success',
            duration: 1000
          });
          this.$emit('changeList', index)
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });


       
      },

       transDate(d) {
      // const date = new Date()
      const date = new Date(d)
      const year = date.getFullYear()
      const month = ('0' + (date.getMonth() + 1)).slice(-2)
      const day = ('0' + (date.getDate())).slice(-2)
      return `${year}-${month}-${day}`
    }


      },
      created(){
      //  this.list=this.dataList
      },
      mounted(){
        
      }
}
</script>

<style lang="less" scoped>
  .article {
    width: 100%;
    background-color: #35205De9;
    border-radius: 20px;
    padding: 40px 80px;
  }
  .article li{
    position: relative;
    width: 100%;
    height: 240px;
    border-radius: 20px;
    background-color: #220F4B;
    padding: 20px 30px 20px 20px;
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    transition: 0.5s;
    cursor: pointer;
  }
  .left{
    height: 100%;
    width: 42%;
    border-radius: 10px;
    overflow: hidden;
  }
  .left img{
    width:100%;
    transition: 0.5s;
  }
  .right{
    width: 54%;
    height: 100%;
    
    
  }
  .right h5{
    width: 96%;
    white-space:nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    color: #00f6ff;
    font-size: 22px;
   
    margin-bottom: 10px;
  }
  .right .detail{
    
    height: 50px;
    line-height: 50px;
    margin-bottom: 30px;
    
  }
  .right .detail .avatar{
    display: inline-block;
   width: 40px;
   height: 40px;
   border-radius: 50%;
   background-color: #000;
   overflow: hidden;
  vertical-align: middle;
   
  }
  .right .detail .avatar img{
    width: 40px;
  }
  
  .right .detail .name{
    display: inline-block;
    width: 30%;
    margin-left: 10px;
    font-size: 16px;
    color: #00f6ff;
  }
  .right .detail .time{
    margin-left: 45%;
    color: #00f6ff;
  }
  .right p{
    color: #bc7dff;
   
    height: 78px;
    line-height: 26px;
    text-overflow:ellipsis;
    overflow: hidden;
  }
  .article li:hover .left img{
    transform: scale(1.08);
  }
  .article li:hover{
    background-color: #8C4FDB;
  }

  .more{
    position: absolute;
    font-size: 30px;
    color: aqua;
    bottom: 10px;
    right: 30px;
    // background-color: #E3C420;
    padding: 0 10px;
}
.more .option{
    z-index: 2;
    position: absolute;

    color: #fff;
    background-color: black;
    top: -50%;
    right: -130%;
    border-radius: 10px;
    // padding: 10px 0;
    text-align: center;
  display: none;

}
.more .option .op{
  padding: 10px 10px;
  border-radius: 10px;
  transition: 0.5s;
}
.more .option .op span{
  margin-right: 10px;
}
.more .option .op:hover{
  background-color: #fff;
  color: #333;
}
.more:hover .option{
  display: block;
}
</style>